export default {
  zhugeinit () {
    window.zhuge = window.zhuge || []
    window.zhuge.methods = '_init debug identify track trackLink trackForm page'.split(' ')
    window.zhuge.factory = function (b) {
      return function () {
        let a = Array.prototype.slice.call(arguments)
        a.unshift(b)
        window.zhuge.push(a)
        return window.zhuge
      }
    }
    for (let i = 0; i < window.zhuge.methods.length; i++) {
      let key = window.zhuge.methods[i]
      window.zhuge[key] = window.zhuge.factory(key)
    }
    window.zhuge.load = function (b, x) {
      if (!document.getElementById('zhuge-js')) {
        let a = document.createElement('script')
        let verDate = new Date()
        let verStr = verDate.getFullYear().toString() +
        verDate.getMonth().toString() + verDate.getDate().toString()

        a.type = 'text/javascript'
        a.id = 'zhuge-js'
        a.async = !0
        a.src = (location.protocol === 'http:' ? 'http://sdk.zhugeio.com/zhuge.min.js?v=' : 'https://zgsdk.zhugeio.com/zhuge.min.js?v=') + verStr
        a.onerror = function () {
          window.zhuge.identify = window.zhuge.track = function (ename, props, callback) {
            if (callback && Object.prototype.toString.call(callback) === '[object Function]') callback()
          }
        }
        let c = document.getElementsByTagName('script')[0]
        c.parentNode.insertBefore(a, c)
        window.zhuge._init(b, x)
      }
    }
    // autoTrack: false启用全埋点采集（选填，默认false）
    // singlePage: false是否是单页面应用（SPA），启用autoTrack后生效（选填，默认false）
    // visualizer: true可视化埋点开关
  }
}
